#!/usr/bin/env python
# -*- coding: utf-8  -*-
#
# This code is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Izaskun Mallona
# izaskun.mallona@gmail.com

"""Fasta file average and std deviation length computer"""

import csv, os
from Bio import SeqIO

print "Starting the assembly sites statistics analysis..."

#vectors to store the lengths
contig = []
singlet = []

#opening the contig's handle
handlePath = os.environ['HOME'] +"/Desktop/Opuntia/our_assembly" +"/O_fic_AllReads_raw.cap.contigs"
handle = open(handlePath, "rU")

#computing length
for record in SeqIO.parse(handle, "fasta"):
    contig.append(len(record.seq))
    
handle.close()

#opening the singlets's handle
handlePath = os.environ['HOME'] +"/Desktop/Opuntia/our_assembly" +"/O_fic_AllReads_raw.cap.singlets"
handle = open(handlePath, "rU")

#computing length
for record in SeqIO.parse(handle, "fasta"):
    singlet.append(len(record.seq))
    
handle.close()

#csv outputs
print "Contig lengths are..."

for item in contig:
    print item

print "Singlets lengths are..."    
for item in singlet:
    print item


print "...finished."

